package cc.xuanhaojituan.mybatis.controller;

import cc.xuanhaojituan.mybatis.domain.User;
import cc.xuanhaojituan.mybatis.service.UserService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderRestController {

	protected static Logger logger = LoggerFactory.getLogger(OrderRestController.class);

	@Autowired
	UserService userService;

	@RequestMapping("/rest/{name}")
	public String helloName(@PathVariable String name) {
		logger.debug("读取helloName,Name={}", name);
		return "Hello " + name;
	}

	@RequestMapping("/user/{id}")
	public User user(@PathVariable int id) {
		return userService.findById(id);
	}

	@RequestMapping("/user")
	public PageInfo<User> users() {
		return userService.findAll("12", null, 1, 10);
	}
	
	@RequestMapping("/user/save")
	public User saveUser() {
		User user = new User();
		user.setUserName("你好");
		userService.save(user);
		return user;
	}

}
